//
//  HomeViewController.m
//  shuiyun
//
//  Created by 马田成 on 2017/9/5.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "HomeViewController.h"
#import "lunboTableViewCell.h"
#import "HomeSecondTableViewCell.h"
#import "HomeDownTableViewCell.h"
#import "HomeThreeCollectionViewCell.h"
#import "BoatMessageViewController.h"
#import "BoatAllianceViewController.h"
#import "HomeDQHYMViewController.h"
#import "HomeCargoInformationVC.h"
#import "HomeShipDangAnViewController.h"
#import "BoatComplaintViewController.h"
#import "HomeZhaoQiuViewController.h"
#import "LogisticsMLViewController.h"
#import "HomeshipJYViewController.h"
@interface HomeViewController ()<UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
{
    
    UICollectionView *downcollectionView;
    
    
    
}
@property (nonatomic, strong) UITableView *tableView;


@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    [self leftNavHide];
    [self regeditCell];
    // Do any additional setup after loading the view.
}
- (void)creationView{

    [self setTitle:@"华东水运网"];
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT- 64 - 49);
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //   self.tableView.estimatedRowHeight = 400;
    
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线
    
    
    [self.view addSubview:self.tableView];
    self.view.backgroundColor = [UIColor colorWithRed:245 / 255.0f green:245 / 255.0f blue:245 / 255.0f alpha:1];

    
}

- (void)regeditCell{
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeSecondTableViewCell" bundle:nil] forCellReuseIdentifier:@"HomeSecondTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeDownTableViewCell" bundle:nil] forCellReuseIdentifier:@"HomeDownTableViewCell"];
    
}
#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 170;
    }else if (indexPath.row == 1) {
        
        return 116;
        
    }else {
        
        return 420;
        
    }
    
    
    
}

#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    if (indexPath.row == 0) {
        
        lunboTableViewCell *cell=(lunboTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"lunboTableViewCell"];
        if (cell == nil) {
            cell=[[lunboTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"lunboTableViewCell"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        if (carouselArr) {
            
            [cell updateInfo:carouselArr];
            
        }
        return cell;
    }else if (indexPath.row == 1) {
    
        HomeSecondTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HomeSecondTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
        [cell.huoYuanButton addTarget:self action:@selector(huoYuanClick) forControlEvents:UIControlEventTouchUpInside];
        
        [cell.chuanYuanButton addTarget:self action:@selector(chuanYuanClick) forControlEvents:UIControlEventTouchUpInside];
        
        return cell;
        
    }else {
        HomeDownTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"HomeDownTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        
        layout.itemSize = CGSizeMake((DEF_SCREEN_WIDTH - 40)  / 3, 130);
        
        downcollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 390 + 30) collectionViewLayout:layout];
        //
        [downcollectionView layoutIfNeeded];
        //    self.automaticallyAdjustsScrollViewInsets = NO;
        downcollectionView.pagingEnabled = NO;
        downcollectionView.delegate = self;
        downcollectionView.dataSource = self;
        
        
        [downcollectionView registerNib:[UINib nibWithNibName:@"HomeThreeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"HomeThreeCollectionViewCell"];
        
        downcollectionView.showsHorizontalScrollIndicator = NO;
        downcollectionView.showsVerticalScrollIndicator = NO;
        
        
        //    self.collectionView.bounces = NO;
        downcollectionView.backgroundColor = [UIColor whiteColor];
        
        [cell addSubview:downcollectionView];
        
        
        
        return cell;

    
        
    }
    
    
    
        
    
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
    
}
//数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    
    return 9;
    
    
}
//内容

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeThreeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeThreeCollectionViewCell" forIndexPath:indexPath];
    NSArray *arrOfTitle = @[@"地区货源", @"船舶交易", @"招聘求职", @"船方联盟", @"联盟排行", @"船舶定位",@"船舶档案",@"物流名录",@"船货投诉"];
    cell.titleLabel.text = arrOfTitle[indexPath.row];
    NSArray *arrOfPic = @[@"home_icon_diqu", @"home_icon_chaunbojiaoyiv", @"home_icon_qiuzhi", @"home_icon_lianmeng", @"home_icon_paiming", @"home_icon_dingwei",@"home_icon_chuanbodangan",@"home_icon_wuliuminglu",@"home_icon_chuanhuotousu"];
    cell.image.image = [UIImage imageNamed:arrOfPic[indexPath.row]];
    
    return cell;
    
    
    
}
//点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    

    if (indexPath.row == 3) {
        
        BoatAllianceViewController * vc = [[BoatAllianceViewController alloc] init];
        
        vc.hidesBottomBarWhenPushed = YES;
        
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 0){
    
        HomeDQHYMViewController *vc = [[HomeDQHYMViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 6){
    
        HomeShipDangAnViewController *vc = [[HomeShipDangAnViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 8){
        
        BoatComplaintViewController *vc = [[BoatComplaintViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    
    }else if (indexPath.row == 2){
    
        HomeZhaoQiuViewController * vc = [[HomeZhaoQiuViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    
    }else if (indexPath.row == 7) {
        
        LogisticsMLViewController *vc = [[LogisticsMLViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 1) {
        
        HomeshipJYViewController *vc = [[HomeshipJYViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.row == 4){
    
        BoatAllianceViewController * vc = [[BoatAllianceViewController alloc] init];
        
        vc.hidesBottomBarWhenPushed = YES;
        
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark - ---------- 货源信息 ----------
- (void)huoYuanClick{

    HomeCargoInformationVC *vc = [[HomeCargoInformationVC alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
   
    
}
#pragma mark - ---------- 船源信息 ----------
- (void)chuanYuanClick{
    BoatMessageViewController * vc = [[BoatMessageViewController alloc] init];
    
    vc.hidesBottomBarWhenPushed = YES;
    
    [self.navigationController pushViewController:vc animated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
